/*
 * relative     : \src\hooks\useFrequency.ts
 * Author       : 郭鹏超
 * Date         : 2025-01-20 16:44
 * LastEditors  : 郭鹏超
 * LastEditTime : 2025-02-11 15:56
 * Description  :
 * CodeIterationRecord:
 */
const frequencies = shallowRef<CascadeOptionsView[]>();
/**
 * @description: 节流的频次获取函数
 * @param useThrottleFn 频次获取函数
 * @return
 */
const throttledFn = useThrottleFn((visibleFlag) => {
  frequencyService.getFrequency({ visibleFlag }).then((res: CascadeOptionsView[]) => {
    frequencies.value = res;
  });
}, 3000);
/**
 * @description: 将频次获取封装进了频次选择器中，会导致频次获取函数短时间内频繁调用，所以需要节流
 */
export function useFrequency() {
  return {
    frequencies,
    /**
     * @description: 获取频次字典
     * @param visibleFlag 是否仅显示可见的频次
     * @return
     */
    getFrequencies: (visibleFlag: boolean) => {
      throttledFn(visibleFlag);
    }
  };
}
